package com.bianguo.android.functiondemo.model;

import com.bianguo.android.functiondemo.retrofit.BaseFunc;
import com.bianguo.android.functiondemo.retrofit.BaseSubscribe;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class BaseModel {

    protected ModelFactory mFactory;

    public BaseModel() {
        mFactory = ModelFactory.getInstance();
    }

    protected <T> void doSubscribe(Observable<T> observable, BaseSubscribe<T> subscribe) {
        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .onErrorResumeNext(new BaseFunc<T>())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscribe);
    }
}
